
    /*********************************************************
    *
    *  Project:      Utilities
    *
    *  Class:        Radicals
    *
    *  File name:    Radicals.java
    *
    *
    *    SVN:
    *
    *    $Rev$:
    *    $Date$:
    *
    *    $LastChangedBy$:
    *
    *    $HeadURL$:
    *
    **********************************************************/

package com.eastmountain.chinese.radicals;

import com.eastmountain.util.DisplayFormats;

/*********************************************************
*
*  Class:        Radicals
*
**********************************************************/

public class Radicals {

    private Radicals() {


    }

    /*********************************************************
    *
    *   radicalNumberToUnicodeCharacter
    *
    *   translate a radical number ( KangXi ) to the
    *   corresponding character value in unicode.
    *
    *   This involves whether we need a traditional or simplified chracter.
    *
    **********************************************************/

    public static String radicalNumberToUnicodeCharacter( int radicalNumber, int simplifiedRadical ) {

        System.out.println( " +++++ Radical number: " + radicalNumber
                            + " Simplified radical: " + simplifiedRadical );

      String unicodeRadical = "";

      if ( simplifiedRadical == 0 ) {

          unicodeRadical  = getRadicalUnicodeValue( radicalNumber );
         
      } else {

          unicodeRadical  = getSimplifiedRadicalUnicodeValue( radicalNumber );

          if ( "\u0020".equals( unicodeRadical) ) {
         	 
         	 unicodeRadical  = getRadicalUnicodeValue( radicalNumber );
         	 
          }

      }

      System.out.println( " Chinese radical: " + DisplayFormats.charToUnicodeString( unicodeRadical.charAt( 0) ) );

      return( unicodeRadical );

    }

    /*********************************************************
    *
    *   getRadicalUnicodeValue
    *
    *   translate a radical number ( KangXi ) to the
    *   corresponding character value in unicode
    *
    **********************************************************/

    public static String getRadicalUnicodeValue( int radicalNumber ) {

        String unicodeValue = "";

        if ( ( radicalNumber >= 0 ) && ( radicalNumber <= 214 ) ) {

            unicodeValue = radicalNumberToUnicode[ radicalNumber ];

        } else {

            // TODO log this

            unicodeValue = radicalNumberToUnicode[ 0 ];

        }

        return( unicodeValue );

    }

    /*********************************************************
    *
    *   getSimplifiedRadicalUnicodeValue
    *
    *   translate a radical number ( KangXi ) to the
    *   corresponding character value in unicode
    *
    **********************************************************/

    public static String getSimplifiedRadicalUnicodeValue( int radicalNumber ) {

        String unicodeValue = "";

        if ( ( radicalNumber >= 0 ) && ( radicalNumber <= 214 ) ) {

            unicodeValue = simplifiedRadicalNumberToUnicode[ radicalNumber ];

        } else {

            // TODO log this

            unicodeValue = simplifiedRadicalNumberToUnicode[ 0 ];

        }

        return( unicodeValue );

    }

    /*********************************************************
    *
    *   getRadicalsWithSimplfiedForms
    *
    *   some radicals for simplified characters have
    *   a simplified radical
    *
    *   Perhaps only to be used to build:
    *
    *     simplifiedRadicalNumberToUnicode
    *
    **********************************************************/

    public static int[] getRadicalsWithSimplfiedForms() {

        return( radicalsWithSimplfiedForm );

    }

    private final static String[] radicalNumberToUnicode = {

        /*   0 */  "",
        /*   1 */  "\u4E00",
        /*   2 */  "\u4E28",
        /*   3 */  "\u4E36",
        /*   4 */  "\u4E3F",
        /*   5 */  "\u4E59",
        /*   6 */  "\u4E85",
        /*   7 */  "\u4E8C",
        /*   8 */  "\u4EA0",
        /*   9 */  "\u4EBA",
        /*  10 */  "\u513F",
        /*  11 */  "\u5165",
        /*  12 */  "\u516B",
        /*  13 */  "\u5182",
        /*  14 */  "\u5196",
        /*  15 */  "\u51AB",
        /*  16 */  "\u51E0",
        /*  17 */  "\u51F5",
        /*  18 */  "\u5200",
        /*  19 */  "\u529B",
        /*  20 */  "\u52F9",
        /*  21 */  "\u5315",
        /*  22 */  "\u531A",
        /*  23 */  "\u5338",
        /*  24 */  "\u5341",
        /*  25 */  "\u535C",
        /*  26 */  "\u5369",
        /*  27 */  "\u5382",
        /*  28 */  "\u53B6",
        /*  29 */  "\u53C8",
        /*  30 */  "\u53E3",
        /*  31 */  "\u56D7",
        /*  32 */  "\u571F",
        /*  33 */  "\u58EB",
        /*  34 */  "\u590A",
        /*  35 */  "\u590A",
        /*  36 */  "\u5915",
        /*  37 */  "\u5927",
        /*  38 */  "\u5973",
        /*  39 */  "\u5B50",
        /*  40 */  "\u5B80",
        /*  41 */  "\u5BF8",
        /*  42 */  "\u5C0F",
        /*  43 */  "\u5C22",
        /*  44 */  "\u5C38",
        /*  45 */  "\u5C6E",
        /*  46 */  "\u5C71",
        /*  47 */  "\u5DDB",
        /*  48 */  "\u5DE5",
        /*  49 */  "\u5DF1",
        /*  50 */  "\u5DFE",
        /*  51 */  "\u5E72",
        /*  52 */  "\u5E7A",
        /*  53 */  "\u5E7F",
        /*  54 */  "\u5EF4",
        /*  55 */  "\u5EFE",
        /*  56 */  "\u5F0B",
        /*  57 */  "\u5F13",
        /*  58 */  "\u5F50",
        /*  59 */  "\u5F61",
        /*  60 */  "\u5F73",
        /*  61 */  "\u5FC3",
        /*  62 */  "\u6208",
        /*  63 */  "\u6236",
        /*  64 */  "\u624B",
        /*  65 */  "\u652F",
        /*  66 */  "\u6534",
        /*  67 */  "\u6587",
        /*  68 */  "\u6597",
        /*  69 */  "\u65A4",
        /*  70 */  "\u65B9",
        /*  71 */  "\u65E0",
        /*  72 */  "\u65E5",
        /*  73 */  "\u66F0",
        /*  74 */  "\u6708",
        /*  75 */  "\u6728",
        /*  76 */  "\u6B20",
        /*  77 */  "\u6B62",
        /*  78 */  "\u6B79",
        /*  79 */  "\u6BB3",
        /*  80 */  "\u6BCD",
        /*  81 */  "\u6BD4",
        /*  82 */  "\u6BDB",
        /*  83 */  "\u6C0F",
        /*  84 */  "\u6C14",
        /*  85 */  "\u6C34",
        /*  86 */  "\u706B",
        /*  87 */  "\u722A",
        /*  88 */  "\u7236",
        /*  89 */  "\u723B",
        /*  90 */  "\u723F",
        /*  91 */  "\u7247",
        /*  92 */  "\u7259",
        /*  93 */  "\u725B",
        /*  94 */  "\u72AC",
        /*  95 */  "\u7384",
        /*  96 */  "\u7389",
        /*  97 */  "\u74DC",
        /*  98 */  "\u74E6",
        /*  99 */  "\u7518",
        /* 100 */  "\u751F",
        /* 101 */  "\u7528",
        /* 102 */  "\u7530",
        /* 103 */  "\u758B",
        /* 104 */  "\u7592",
        /* 105 */  "\u7676",
        /* 106 */  "\u767D",
        /* 107 */  "\u76AE",
        /* 108 */  "\u76BF",
        /* 109 */  "\u76EE",
        /* 110 */  "\u77DB",
        /* 111 */  "\u77E2",
        /* 112 */  "\u77F3",
        /* 113 */  "\u793A",
        /* 114 */  "\u79B8",
        /* 115 */  "\u79BE",
        /* 116 */  "\u7A74",
        /* 117 */  "\u7ACB",
        /* 118 */  "\u7AF9",
        /* 119 */  "\u7C73",
        /* 120 */  "\u7CF8",
        /* 121 */  "\u7F36",
        /* 122 */  "\u7F51",
        /* 123 */  "\u7F8A",
        /* 124 */  "\u7FBD",
        /* 125 */  "\u8001",
        /* 126 */  "\u800C",
        /* 127 */  "\u8012",
        /* 128 */  "\u8033",
        /* 129 */  "\u807F",
        /* 130 */  "\u8089",
        /* 131 */  "\u81E3",
        /* 132 */  "\u81EA",
        /* 133 */  "\u81F3",
        /* 134 */  "\u81FC",
        /* 135 */  "\u820C",
        /* 136 */  "\u821B",
        /* 137 */  "\u821F",
        /* 138 */  "\u826E",
        /* 139 */  "\u8272",
        /* 140 */  "\u8278",
        /* 141 */  "\u864D",
        /* 142 */  "\u866B",
        /* 143 */  "\u8840",
        /* 144 */  "\u884C",
        /* 145 */  "\u8863",
        /* 146 */  "\u897E",
        /* 147 */  "\u898B",
        /* 148 */  "\u89D2",
        /* 149 */  "\u8A00",  // TODO this may be 8A01
        /* 150 */  "\u8C37",
        /* 151 */  "\u8C46",
        /* 152 */  "\u8C55",
        /* 153 */  "\u8C78",
        /* 154 */  "\u8C9D",
        /* 155 */  "\u8D64",
        /* 156 */  "\u8D70",
        /* 157 */  "\u8DB3",
        /* 158 */  "\u8EAB",
        /* 159 */  "\u8ECA",
        /* 160 */  "\u8F9B",
        /* 161 */  "\u8FB0",
        /* 162 */  "\u8FB5",
        /* 163 */  "\u9091",
        /* 164 */  "\u9149",
        /* 165 */  "\u91C6",
        /* 166 */  "\u91CC",
        /* 167 */  "\u91D1",
        /* 168 */  "\u9577",
        /* 169 */  "\u9580",
        /* 170 */  "\u961C",
        /* 171 */  "\u96B6",
        /* 172 */  "\u96B9",
        /* 173 */  "\u96E8",
        /* 174 */  "\u9751",
        /* 175 */  "\u975E",
        /* 176 */  "\u9762",
        /* 177 */  "\u9769",
        /* 178 */  "\u97CB",
        /* 179 */  "\u97ED",
        /* 180 */  "\u97F3",
        /* 181 */  "\u9801",
        /* 182 */  "\u98A8",
        /* 183 */  "\u98DB",
        /* 184 */  "\u98DF",
        /* 185 */  "\u9996",
        /* 186 */  "\u9999",
        /* 187 */  "\u99AC",
        /* 188 */  "\u9AA8",
        /* 189 */  "\u9AD8",
        /* 190 */  "\u9ADF",
        /* 191 */  "\u9B25",
        /* 192 */  "\u9B2F",
        /* 193 */  "\u9B32",
        /* 194 */  "\u9B3C",
        /* 195 */  "\u9B5A",
        /* 196 */  "\u9CE5",
        /* 197 */  "\u9E75",
        /* 198 */  "\u9E7F",
        /* 199 */  "\u9EA5",
        /* 200 */  "\u9EBB",
        /* 201 */  "\u9EC3",
        /* 202 */  "\u9ECD",
        /* 203 */  "\u9ED1",
        /* 204 */  "\u9EF9",
        /* 205 */  "\u9EFD",
        /* 206 */  "\u9F0E",
        /* 207 */  "\u9F13",
        /* 208 */  "\u9F20",
        /* 209 */  "\u9F3B",
        /* 210 */  "\u9F4A",
        /* 211 */  "\u9F52",
        /* 212 */  "\u9F8D",
        /* 213 */  "\u9F9C",
        /* 214 */  "\u9FA0"

    };

    private final static String[] simplifiedRadicalNumberToUnicode = {

    // TODO this may not be correct
    	
    /*   0 */  "\u0020",
    /*   1 */  "\u0020",
    /*   2 */  "\u0020",
    /*   3 */  "\u0020",
    /*   4 */  "\u0020",
    /*   5 */  "\u0020",
    /*   6 */  "\u0020",
    /*   7 */  "\u0020",
    /*   8 */  "\u0020",
    /*   9 */  "\u0020",
    /*  10 */  "\u0020",
    /*  11 */  "\u0020",
    /*  12 */  "\u0020",
    /*  13 */  "\u0020",
    /*  14 */  "\u0020",
    /*  15 */  "\u0020",
    /*  16 */  "\u0020",
    /*  17 */  "\u0020",
    /*  18 */  "\u0020",
    /*  19 */  "\u0020",
    /*  20 */  "\u0020",
    /*  21 */  "\u0020",
    /*  22 */  "\u0020",
    /*  23 */  "\u0020",
    /*  24 */  "\u0020",
    /*  25 */  "\u0020",
    /*  26 */  "\u0020",
    /*  27 */  "\u0020",
    /*  28 */  "\u0020",
    /*  29 */  "\u0020",
    /*  30 */  "\u0020",
    /*  31 */  "\u0020",
    /*  32 */  "\u0020",
    /*  33 */  "\u0020",
    /*  34 */  "\u0020",
    /*  35 */  "\u0020",
    /*  36 */  "\u0020",
    /*  37 */  "\u0020",
    /*  38 */  "\u0020",
    /*  39 */  "\u0020",
    /*  40 */  "\u0020",
    /*  41 */  "\u0020",
    /*  42 */  "\u0020",
    /*  43 */  "\u0020",
    /*  44 */  "\u0020",
    /*  45 */  "\u0020",
    /*  46 */  "\u0020",
    /*  47 */  "\u0020",
    /*  48 */  "\u0020",
    /*  49 */  "\u0020",
    /*  50 */  "\u0020",
    /*  51 */  "\u0020",
    /*  52 */  "\u0020",
    /*  53 */  "\u0020",
    /*  54 */  "\u0020",
    /*  55 */  "\u0020",
    /*  56 */  "\u0020",
    /*  57 */  "\u0020",
    /*  58 */  "\u0020",
    /*  59 */  "\u0020",
    /*  60 */  "\u0020",
    /*  61 */  "\u0020",
    /*  62 */  "\u0020",
    /*  63 */  "\u0020",
    /*  64 */  "\u0020",
    /*  65 */  "\u0020",
    /*  66 */  "\u0020",
    /*  67 */  "\u0020",
    /*  68 */  "\u0020",
    /*  69 */  "\u0020",
    /*  70 */  "\u0020",
    /*  71 */  "\u0020",
    /*  72 */  "\u0020",
    /*  73 */  "\u0020",
    /*  74 */  "\u0020",
    /*  75 */  "\u0020",
    /*  76 */  "\u0020",
    /*  77 */  "\u0020",
    /*  78 */  "\u0020",
    /*  79 */  "\u0020",
    /*  80 */  "\u0020",
    /*  81 */  "\u0020",
    /*  82 */  "\u0020",
    /*  83 */  "\u0020",
    /*  84 */  "\u0020",
    /*  85 */  "\u0020",
    /*  86 */  "\u0020",
    /*  87 */  "\u0020",
    /*  88 */  "\u0020",
    /*  89 */  "\u0020",
    /*  90 */  "\u0020",
    /*  91 */  "\u0020",
    /*  92 */  "\u0020",
    /*  93 */  "\u0020",
    /*  94 */  "\u0020",
    /*  95 */  "\u0020",
    /*  96 */  "\u0020",
    /*  97 */  "\u0020",
    /*  98 */  "\u0020",
    /*  99 */  "\u0020",
    /* 100 */  "\u0020",
    /* 101 */  "\u0020",
    /* 102 */  "\u0020",
    /* 103 */  "\u0020",
    /* 104 */  "\u0020",
    /* 105 */  "\u0020",
    /* 106 */  "\u0020",
    /* 107 */  "\u0020",
    /* 108 */  "\u0020",
    /* 109 */  "\u0020",
    /* 110 */  "\u0020",
    /* 111 */  "\u0020",
    /* 112 */  "\u0020",
    /* 113 */  "\u0020",
    /* 114 */  "\u0020",
    /* 115 */  "\u0020",
    /* 116 */  "\u0020",
    /* 117 */  "\u0020",
    /* 118 */  "\u0020",
    /* 119 */  "\u0020",
    /* 120 */  "\u0020",
    /* 121 */  "\u0020",
    /* 122 */  "\u0020",
    /* 123 */  "\u0020",
    /* 124 */  "\u0020",
    /* 125 */  "\u0020",
    /* 126 */  "\u0020",
    /* 127 */  "\u0020",
    /* 128 */  "\u0020",
    /* 129 */  "\u0020",
    /* 130 */  "\u0020",
    /* 131 */  "\u0020",
    /* 132 */  "\u0020",
    /* 133 */  "\u0020",
    /* 134 */  "\u0020",
    /* 135 */  "\u0020",
    /* 136 */  "\u0020",
    /* 137 */  "\u0020",
    /* 138 */  "\u0020",
    /* 139 */  "\u0020",
    /* 140 */  "\u0020",
    /* 141 */  "\u0020",
    /* 142 */  "\u0020",
    /* 143 */  "\u0020",
    /* 144 */  "\u0020",
    /* 145 */  "\u0020",
    /* 146 */  "\u0020",
    /* 147 */  "\u89C1",
    /* 148 */  "\u0020",
    /* 149 */  "\u0020",
    /* 150 */  "\u0020",
    /* 151 */  "\u0020",
    /* 152 */  "\u0020",
    /* 153 */  "\u0020",
    /* 154 */  "\u8D1D",
    /* 155 */  "\u0020",
    /* 156 */  "\u0020",
    /* 157 */  "\u0020",
    /* 158 */  "\u0020",
    /* 159 */  "\u8F66",
    /* 160 */  "\u0020",
    /* 161 */  "\u0020",
    /* 162 */  "\u0020",
    /* 163 */  "\u0020",
    /* 164 */  "\u0020",
    /* 165 */  "\u0020",
    /* 166 */  "\u0020",
    /* 167 */  "\u0020",
    /* 168 */  "\u957F",
    /* 169 */  "\u95E8",
    /* 170 */  "\u0020",
    /* 171 */  "\u0020",
    /* 172 */  "\u0020",
    /* 173 */  "\u0020",
    /* 174 */  "\u0020",
    /* 175 */  "\u0020",
    /* 176 */  "\u0020",
    /* 177 */  "\u0020",
    /* 178 */  "\u97E6",
    /* 179 */  "\u0020",
    /* 180 */  "\u0020",
    /* 181 */  "\u9875",
    /* 182 */  "\u98CE",
    /* 183 */  "\u98DE",
    /* 184 */  "\u0020",
    /* 185 */  "\u0020",
    /* 186 */  "\u0020",
    /* 187 */  "\u9A6C",
    /* 188 */  "\u0020",
    /* 189 */  "\u0020",
    /* 190 */  "\u0020",
    /* 191 */  "\u0020",
    /* 192 */  "\u0020",
    /* 193 */  "\u0020",
    /* 194 */  "\u0020",
    /* 195 */  "\u9C7C",
    /* 196 */  "\u9E1F",
    /* 197 */  "\u5364",
    /* 198 */  "\u0020",
    /* 199 */  "\u9EA6",
    /* 200 */  "\u0020",
    /* 201 */  "\u0020",
    /* 202 */  "\u0020",
    /* 203 */  "\u0020",
    /* 204 */  "\u0020",
    /* 205 */  "\u9EFE",
    /* 206 */  "\u0020",
    /* 207 */  "\u0020",
    /* 208 */  "\u0020",
    /* 209 */  "\u0020",
    /* 210 */  "\u9F50",
    /* 211 */  "\u9F7F",
    /* 212 */  "\u9F99",
    /* 213 */  "\u9F9F",
    /* 214 */  "\u0020"

    };

    // 120 = 7E9F

    private final static int[] radicalsWithSimplfiedForm = {

    120,
    147,
    149,
    154,
    159,
    167,
    168,
    169,
    178,
    181,
    182,
    183,
    184,
    187,
    195,
    196,
    197,
    199,
    205,
    210,
    211,
    212,
    213

    };

}
